package cn.faster.config.filter;

import cn.faster.config.security.xss.XssWrapper;
import lombok.extern.log4j.Log4j2;

import javax.servlet.*;
import javax.servlet.FilterConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author xiaoCoder
 * @version 1.0
 * @description: TODO
 * @date 2021/8/9 17:13
 */
@Log4j2
public class XssFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        log.info("uri:{}", request.getRequestURI());
        // 进行 Xss 过滤
        filterChain.doFilter(new XssWrapper(request), response);

    }

    @Override
    public void destroy() {

    }
}
